import Mock from 'mockjs2'
import { builder, getBody, getQueryParameters } from '../util'

const login = options => {
  console.log('options', options)
  const data = {
    token: 'xxxxxxxxxxx'
  }
  return builder(data)
}
  
const getInfo = options => {
	let query = getQueryParameters(options)
  console.log('query', query)
  const data = {
    nickname: '管理员',
	avatar: undefined
  }
  return builder(data)
}

const searchList = options => {
  let query = getQueryParameters(options)
  console.log('query', query)
  return builder({
	  total: 20,
	  current: query.current,
	  pageSize: query.pageSize,
	  record: [
		  {
			  id: 1,
			  username: 'cold',
			  nickname: 'cold',
			  gender: 0,
			  birthday: '1970-01-01',
			  mobile: '111111111',
			  email: 'qqqqqqqq',
			  enabled: 1
		  },
		  {
		  			  id: 2,
		  			  username: 'cold',
		  			  nickname: 'cold',
		  			  gender: 1,
		  			  birthday: '1970-01-01',
		  			  mobile: '111111111',
		  			  email: 'qqqqqqqq',
					  enabled: 0
		  },
		  {
		  			  id: 3,
		  			  username: 'cold',
		  			  nickname: 'cold',
		  			  gender: 2,
		  			  birthday: '1970-01-01',
		  			  mobile: '111111111',
		  			  email: 'qqqqqqqq',
					  enabled: 1
		  }
	  ]
  })
}

const saveUser = options => {
  let body = getBody(options)
  console.log('body', body)
  return builder(null)
}

const modifyUser = options => {
  let body = getBody(options)
  console.log('body', body)
  return builder(null)
}

const removeUser = options => {
  let body = getBody(options)
  console.log('body', body)
  return builder(null)
}

const modifyPasswd = options => {
  let body = getBody(options)
  console.log('body', body)
  return builder(null)
}
  
Mock.mock(/\/api\/user\/login/, 'post', login)
Mock.mock(/\/api\/user\/getInfo/, 'get', getInfo)
Mock.mock(/\/api\/user\/searchList/, 'get', searchList)
Mock.mock(/\/api\/user\/save/, 'post', saveUser)
Mock.mock(/\/api\/user\/modify/, 'post', modifyUser)
Mock.mock(/\/api\/user\/remove/, 'post', removeUser)
Mock.mock(/\/api\/user\/modifyPasswd/, 'post', modifyPasswd)
